﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CreatePGSQLDataScript
{
    public class historyList
    {
        public static void ReadList(System.Windows.Forms.ComboBox cmb1)
        {
            string code = cmb1.Tag.ToString();
            List<string> list1 = new List<string>();
            for(int i=1;i<=5;i++)
            {
                try
                {
                    string value = DataAccess.SystemSettings.getSetting(code + i.ToString());
                    list1.Add(value);
                }
                catch
                {
                }
            }
            cmb1.DataSource = list1;
        }

        public static void SaveValue(System.Windows.Forms.ComboBox cmb1)
        {

            string code=cmb1.Tag.ToString();
            string selectedValue = cmb1.Text;
            int currNodeIndex = 5;
            for (int i = 1; i <= 5; i++)
            {
                string nodeName = code + i.ToString();
                string value2 = DataAccess.SystemSettings.getSetting(nodeName);
                if (value2 == selectedValue)
                {
                    currNodeIndex = i; //已存在，不需要保存
                }
            }

            //往上移動
            for(int k=currNodeIndex;k>1;k--)
            {
                string tempValue1=DataAccess.SystemSettings.getSetting(code + (k-1).ToString());
                string tempValue2=DataAccess.SystemSettings.getSetting(code + k.ToString());

                DataAccess.SystemSettings.saveSetting(code + k.ToString(), tempValue1);
                DataAccess.SystemSettings.saveSetting(code + (k - 1).ToString(), tempValue2);
            }

            DataAccess.SystemSettings.saveSetting(code + "1", selectedValue);
        }
    }
}
